namespace Maple.Branch.Settings.EfCoreRepositories
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using EfCoreConfigurations;
    using Entities;
    using IRepositories;
    using Microsoft.EntityFrameworkCore;
    using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
    using Volo.Abp.EntityFrameworkCore;

    public class SettingRepository : EfCoreRepository<ISettingsDbContext, Setting, Guid>, ISettingRepository
    {
        public SettingRepository(IDbContextProvider<ISettingsDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey)
        {
            return await DbSet.FirstOrDefaultAsync(s =>
            s.Name == name
            && s.ProviderName == providerName
            && s.ProviderKey == providerKey
            );
        }

        public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey)
        {
            return await DbSet.Where(s =>
            s.ProviderName == providerName
            && s.ProviderKey == providerKey
            ).ToListAsync();
        }
    }
}
